var getMessageTask=null;
$(function () {

    $(".content-left-submenu ul li ").click(function () {

        if (event.stopPropagation) {
            // 针对 Mozilla 和 Opera
            event.stopPropagation();
        }else if (window.event) {
            // 针对 IE
            window.event.cancelBubble = true;
        }

            var thisSpan = $(this);
        // $(this).children("a").children("i").css("menu-icon-right")=='none'
        if ($(this).children('ul').css('display') == 'none') {
            $(this).children("a").children("i").removeClass("menu-icon-down");
            $(this).children("a").children("i").addClass("menu-icon-right");

            $(this).siblings().children("a").children("i").addClass("menu-icon-right");
            // $(".content-left-submenu ul li a i").prev().removeClass("menu-icon-right");
            // $("ul", this).prev("i").addClass("menu-icon-down");
            $(this).children("ul").slideDown("fast");
            $(this).siblings().children("ul").slideUp("fast");
        } else {
            $(this).children("a").children("i").removeClass("menu-icon-right");
            $(this).children("a").children("i").addClass("menu-icon-down");
            $(this).children("ul").slideUp("fast");
        }
    });
    $("#topQuery .content-button").click(function () {
        $("#topQuery .content-button").removeClass("checkBtn");
        $(this).addClass("checkBtn");
        var epsId = $(".checkLi").attr("dataId");
        var status = $(this).val();
        var projectName = $("#projectName").val();
        /*if (epsId != null && epsId != "" && epsId != undefined) {
         $("#datamain").attr("src", "/homepage/findProjectCountByEpsId?epsId=" + epsId+"&&status="+status+"&&projectName="+projectName);
         }*/
        if (epsId == undefined) {
            epsId = 0;
        }
        $("#datamain").attr("src", "/homepage/findProjectCountByEpsId?epsId=" + epsId + "&&status=" + status + "&&projectName=" + projectName);
    });
    $("#search").click(function () {
        var epsId = $(".checkLi").attr("dataId");
        var status = $(".checkBtn").val();
        if (status == undefined) {
            status = 3;
        }
        var projectName = $("#projectName").val();
        if (epsId == undefined) {
            epsId = 0;
        }
        $("#datamain").attr("src", "/homepage/findProjectCountByEpsId?epsId=" + epsId + "&&status=" + status + "&&projectName=" + encodeURI(projectName));
    });
    init();

});
function init() {
    getMessage();
    setInterval("getMessage()", 30000);
    // $("#datamain").attr("src", "/homepage/findProjectCountByEpsId");
    $(".content-left-submenu ul li").children("ul").slideDown();
}
function addTabs(id, name, type) {
    // $("#topQuery .content-button").removeClass("checkBtn");
    $("#sidebar").find("span").removeClass("checkLi");
    $("#checkColor" + id).addClass("checkLi");
    // var id = $(this).find("a").attr("id");
    var status = $(".checkBtn").val();
    if (status == undefined) {
        status = 3;
    }
    var projectName = $("#projectName").val();
    // $("#statistics").hide();
    // $("#datamain").attr("src", "/homepage/findProjectCountByEpsId?epsId=" + id);//.show();
    $("#datamain").attr("src", "/homepage/findProjectCountByEpsId?epsId=" + id + "&&status=" + status + "&&projectName=" + projectName);
}
function getMessage() {
    var url="/homepage/findMessage?"+ "newDate=" + (new Date().getTime());;
    $.ajax({
        url: url,
        type: "post",
        dataType: "json",
        success: function (data) {
            if (getMessageTask != null) {
                clearInterval(getMessageTask);
            }

            var messageHtml = "<ul>";
            for (var i = data.length-1; i >=0; i--) {debugger
                messageHtml+="<li style='  overflow: hidden; '>" +
                    "<a style='color:#333;text-decoration : none  ' href='javascript:lookMessage("+data[i].id+");'" +
                    " >"
                    +data[i].infotitle+":"+data[i].infocontent;
                    if(data[i].closeMemo !=undefined&&data[i].closeMemo!=null&&data[i].closeMemo !=""){
                        messageHtml+= "<span style='color: red'>"+ data[i].closeMemo+"</span>"
                    }

                messageHtml+=   "</a></li>";
            }
            messageHtml += "</ul>";
            $("#message-main").html(messageHtml);
            $("#message-main ul").find('li:first').show();

            getMessageTask=  setInterval("lunbo('#message-main ul','-50px')", 3000)
        }
    })

}
function lunbo(id, height) {
    var ul = $(id);
    var liFirst = ul.find('li:first');
    $(id).animate({top: height}).animate({"top": 0}, 0, function () {
        var clone = liFirst.clone().hide();
        // clone.attr("hidden","hidden");
        $(id).append(clone);
        liFirst.remove();
        ul.find('li:first').show();
    })
}
function lookMessage(id) {
    pageii = layer.open({
        title: "消息详情",
        type: 2,
        fixed: true,
        //shadeClose : true,
        area: ["600px", "550px"],
        content: "/homepage/findMessageDetailsUI?messageId=" +id
    });
}